<!--
 * @Author: weikang
 * @Description:
 * @Date: 2023-12-22 22:15:35
 * @LastEditTime: 2024-03-19 14:01:54
 * @FilePath: \env-manager-pc\src\views\document\statistics\qiyefenbu.vue
-->
<script setup lang="ts">
import * as Echarts from 'echarts'
import useDashboardStore from '@/store/modules/dashboard'

const dashboardStore = useDashboardStore()

const option = computed(() => {
  return {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'shadow',
      },
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true,
    },
    xAxis: {
      type: 'category',
      data: dashboardStore.envDashboard?.EnvOrgs?.map((item: any) => item.EnvOrgName) || [],
      axisTick: {
        alignWithLabel: true,
      },
    },
    yAxis: {
      name: '单位：家',
      type: 'value',
    },
    series: [
      {
        name: '企业分布情况',
        type: 'bar',
        barWidth: '40%',
        data: dashboardStore.envDashboard?.EnvOrgs?.map((item: any) => item.EntNum) || [],
      },
    ],
  }
})

const chartRef = ref<any>()
let chart: any = null
onMounted(() => {
  chart = Echarts.init(chartRef.value)
  chart.setOption(option.value)
  window.addEventListener('resize', () => {
    chart.resize()
  })
})

dashboardStore.$subscribe((mutation, state) => {
  if (state.envDashboard?.EnvOrgs) {
    chart.setOption(option.value)
  }
})
</script>

<template>
  <PageMain title="企业分布情况">
    <div ref="chartRef" class="h-[30vh] min-h-[300px] w-full overflow-hidden" />
  </PageMain>
</template>
